--[[日志类 用于输出打印
]]
local json = require("json")
local M = {}

ISPRINT = true

local function getPrintPosInfo()
	local source = debug.getinfo(3, "S")
	local line = debug.getinfo(3, "l")

	local info = "-------- " .. string.sub(source.source, -30) .. "  line:" .. line.currentline ..  " --------"

	return info
end

-- 打印表
function M.printT(t1)
	if not ISPRINT then
		return
	end

	local info = getPrintPosInfo()

	print(info)

	print(json.prettify(t1))
	
	print(info)
end

-- 正常的打印
function M.print(...)
	if not ISPRINT then
		return
	end

	local info = getPrintPosInfo()

	print(info)

	print(...)
	
	print(info)
end

-- warning 级别
function M.warning(...)
	if not ISPRINT then
		return
	end

	local info = getPrintPosInfo()

	print(info)

	infoStr = infoStr or ""
	print("warning: ")
	print(...)
	
	print(info)
end

-- error 级别
function M.error(...)
	if not ISPRINT then
		return
	end
	local tInfo = {...}
	local info = getPrintPosInfo()

	print(info)

	print("error: ")

	for k, v in pairs(tInfo) do
		if type(v) == "table" then
			print(json.prettify(v))
		else
			print(v)
		end
	end
	
	print(info)
end

-- 打印调用堆栈
function M.printStack()
	if not ISPRINT then
		return
	end

	local info = getPrintPosInfo()

	print(info)

	print(debug.traceback())
	
	print(info)
end

return M